package com.xhej.router.netease.service.impl;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class NeteaseServiceImpl {
	

	// 1:云信注册接口
	
	// 2:关注关系导入(注册用)
	// 3:云信加关注功能接口 主要提供给xej关注功能使用
	public static void main(String[] args) throws Exception {
		
		curl -X POST -H  -H  -H  -H -H  -d 'accid=zhangsan&faccid=lisi&type=1' 'https://api.netease.im/nimserver/friend/add.action'
		// TODO 查询用户信息接口  注册网易云信服务获取用户原始信息
        DefaultHttpClient httpClient = new DefaultHttpClient();
        String url = "https://api.netease.im/nimserver/friend/add.action"; // 发送网易云信注册请求接口
        HttpPost httpPost = new HttpPost(url);

        String appKey = NeteaseConstans.APPKEY_VALUE;
        String appSecret = NeteaseConstans.APPSECRET_VALUE;
        String nonce =  "12345";
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码

        // 设置请求的header
        httpPost.addHeader(NeteaseConstans.APPKEY_KEY, appKey);
        httpPost.addHeader(NeteaseConstans.NONCE_KEY, nonce);
        httpPost.addHeader(NeteaseConstans.CURTIME_KEY, curTime);
        httpPost.addHeader(NeteaseConstans.CHECKSUM_KEY, checkSum);
        httpPost.addHeader(NeteaseConstans.CONTENT_TYPE_KEY, NeteaseConstans.CONTENT_TYPE_VALUE);

        // 设置请求的参数
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(NeteaseConstans.ACCID_KEY, "wjh9"));
        nvps.add(new BasicNameValuePair("faccid", "wjh9"));
        nvps.add(new BasicNameValuePair("type", "1"));
        nvps.add(new BasicNameValuePair("ex", "1"));// 1
        nvps.add(new BasicNameValuePair("alias", "1"));// 备注名
//        nvps.add(new BasicNameValuePair(NeteaseConstans.ICON_KEY, "")) ;
        
	}
	
	// 4:云信取消关注功能接口
	// 5:云信修改用户信息功能接口

}
